package homework13;

import java.util.ArrayList;
import java.util.Collections;

public class home01 extends Thread{
    ArrayList<Integer> list;
    Integer sumprize=0;
    Integer maxprize;

    public home01(ArrayList<Integer> list) {
        this.list = list;
    }

    public Integer getSumprize() {
        return sumprize;
    }

    public void setSumprize(Integer sumprize) {
        this.sumprize = sumprize;
    }

    @Override
    public void run() {
        StringBuilder sb=new StringBuilder();
        sb.append(getName()+":");
        while (true){
            synchronized (home01.class){
                if(list.size() == 0){
                    break;
                }
                Collections.shuffle(list);
                Integer prize=list.remove(0);
                setSumprize(sumprize+prize);
//                System.out.print(prize+",");
                sb.append(prize+",");
                try {
                    sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        sb.append("总计额为"+getSumprize()+"元");
        System.out.println(sb);
    }
}
